﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Solicitud_Seleccion
''' </summary>
''' <remarks></remarks>
Public Class TDGSolicitud_Seleccion

    Private Shared m_Instance As TDGSolicitud_Seleccion = Nothing


    Public Function Insert(conn As SqlConnection, _
                           Busq_Numero As Int16, _
                           Sel_Numero As Int16, _
                           Soli_Numero As Int32, _
                           SolSelObs As String) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addSolicitud_Seleccion"
        command.Parameters.AddWithValue("@Busq_Numero", Busq_Numero)
        command.Parameters.AddWithValue("@Sel_Numero", Sel_Numero)
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)
        command.Parameters.AddWithValue("@SolSelObs", SolSelObs)


        iRowsAffected = command.ExecuteNonQuery()


        Return iRowsAffected

    End Function

    Public Function Delete(conn As SqlConnection, _
                           Busq_Numero As Int16, _
                           Sel_Numero As Int16, _
                           Soli_Numero As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure
        command.CommandText = "dbo.delSolicitud_Seleccion"
        command.Parameters.AddWithValue("@Busq_Numero", Busq_Numero)
        command.Parameters.AddWithValue("@Sel_Numero", Sel_Numero)
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find(conn As SqlConnection, _
                         Busq_Numero As Int16, _
                         Sel_Numero As Int16, _
                         Soli_Numero As Int32) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getSolicitud_Seleccion"
        command.Parameters.AddWithValue("@Busq_Numero", Busq_Numero)
        command.Parameters.AddWithValue("@Sel_Numero", Sel_Numero)
        command.Parameters.AddWithValue("@Soli_Numero", Soli_Numero)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAllPorBusqueda(conn As SqlConnection, _
                                       Busq_Numero As Int16, _
                                       Sel_Numero As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getSolicitud_Seleccion_PorSeleccion"

        command.Parameters.AddWithValue("@Busq_Numero", Busq_Numero)
        command.Parameters.AddWithValue("@Sel_Numero", Sel_Numero)

        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGSolicitud_Seleccion()
            End If

            Return m_Instance
        End Get
    End Property

End Class
